import express from 'express';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import cors from 'cors';

import { swagger } from './src/utils/swagger/swagger.js';

const app = express();
dotenv.config();

const PORT = process.env.PORT || 3001;
const DB_USER = process.env.DB_USER;
const DB_PASSWORD = process.env.DB_PASSWORD;
const DB_NAME = process.env.DB_NAME;

app.use(cors());
app.use(express.json());

// --- Код ---
// --- Код ---

async function start() {
    try {
        await mongoose
            .connect(`mongodb+srv://${DB_USER}:${DB_PASSWORD}@cluster0.1is4eml.mongodb.net/${DB_NAME}`)
            .then(console.log('База данных подключена'));
        // await mongoose.connect(process.env.MONGO_URL)

        app.listen(PORT, () => {
            console.log(`Сервер запущен на порте ${PORT}`);

            swagger(app, PORT);

            console.log(`API SWAGGER: http://localhost:${PORT}/api/docs`);
        });
    } catch (error) {
        console.log(error);
    }
}

start();
